<template>
  <div>
    <Zenduan :records="records" @Search="search" @Show="newshow"></Zenduan>
    <TanCuan v-show="isShow" :list="list" @space="Space"></TanCuan>
  </div>
</template>

<script>
import Zenduan from './components/zen-daun.vue'
import TanCuan from './components/tan-cuan.vue'

export default {
  components: {
    Zenduan,
    TanCuan,
  },

  data() {
    return {
      list: {},
      isShow: false,
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药',
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药',
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴',
        },
      ],
    }
  },
  methods: {
    search(val) {
      if (val === '') {
        this.records = [
          {
            date: '2022-01-01',
            doctor: '张三',
            diagnosis: '感冒',
            prescription: '感冒药',
          },
          {
            date: '2022-02-01',
            doctor: '李四',
            diagnosis: '头疼',
            prescription: '止疼药',
          },
          {
            date: '2022-03-01',
            doctor: '王五',
            diagnosis: '腰痛',
            prescription: '止痛贴',
          },
        ]
      } else {
        this.records = this.records.filter(
          (item) => item.doctor.indexOf(val) > -1
        )
      }
    },
    newshow(val) {
      this.list = this.records.find((item) => item.doctor === val)
      // console.log(this.list)
      this.isShow = !this.isShow
    },
    Space() {
      this.isShow = !this.isShow
    },
  },
}
</script>

<style></style>
